package com.dashang.view.action;

import java.util.List;

import org.apache.commons.lang.xwork.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.dashang.entity.UserInfo;
import com.dashang.services.IUserServices;

/**
 *
 * 登录Action
 *
 * @author 陈兴
 * @version [版本号, 2011-8-28]
 * @see [相关类/方法]
 * @since [产品/模块版本]
 */
public class LoginAction extends BaseAction
{
    /**
     * serialVersionUID
     */
    private static final long serialVersionUID = 2083558258157219806L;

    /**
     * 日志对象
     */
    private static final Log log = LogFactory.getLog(LoginAction.class);

    /**
     * 登录用户
     */
    private UserInfo userInfo;

    /**
     * 用户接口
     */
    private IUserServices userServices;

    /**
     * 登录
     *
     * @return 登录页面
     * @see [类、类#方法、类#成员]
     */
    public String checkLogin()
    {
        log.debug("logging username :" + userInfo.getLoginName());

        String password = userInfo.getPassword();
        if (StringUtils.isNotEmpty(userInfo.getLoginName()) && StringUtils.isNotEmpty(password))
        {
            List<UserInfo> queryUser = userServices.queryUserWithRF(userInfo); // 查询用户信息
            System.out.println(queryUser);
//            if (null != queryUser && queryUser.getPassword().equals(MD5Util.EncoderByMd5(password))) // 登录成功
//            {
//                request.getSession().setAttribute(SystemConstant.LOGIN_USER, queryUser); // 保存会话用户
//                return SUCCESS;
//            }
        }
        return INPUT;
    }

    public UserInfo getUserInfo()
    {
        return userInfo;
    }

    public void setUserInfo(UserInfo userInfo)
    {
        this.userInfo = userInfo;
    }

    public IUserServices getUserServices()
    {
        return userServices;
    }

    public void setUserServices(IUserServices userServices)
    {
        this.userServices = userServices;
    }
}
